/**
 * @projectName: petJoyHome
 * @author: 小飞
 * @description: TODO
 * @date: 2024/3/1 14:34
 * @version: 1.0
 */
package com.home.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * 返回状态码类
 * @param <T>
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    private int code; //返回的状态码
    private String msg; //返回的信息
    private T data; // 返回的数据
    private long timestamp; //返回时间戳

    public static <T> Result<T> success(){
        Result<T> result =  new Result<>();
        result.code = ResultCode.SUCCESS.getCode();
        result.timestamp= System.currentTimeMillis();
        return result;
    }

    public static <T> Result<T> success(String msg){
        Result<T> result =  new Result<>();
        result.code = ResultCode.SUCCESS.getCode();
        result.msg = msg;
        result.timestamp= System.currentTimeMillis();
        return result;
    }
    public static <T> Result<T> success(String msg,T data){
        Result<T> result = new Result<>();
        result.code = ResultCode.SUCCESS.getCode();
        result.msg = msg;
        result.data = data;
        result.timestamp= System.currentTimeMillis();
        return result;
    }

    public static <T> Result<T> failed(String msg){
        Result<T> result =  new Result<>();
        result.msg = msg;
        result.code = ResultCode.FAILED.getCode();
        result.timestamp= System.currentTimeMillis();
        return result;
    }

    public static <T> Result<T> failed(int code,String msg){
        Result<T> result =  new Result<>();
        result.msg = msg;
        result.code = code;
        result.timestamp= System.currentTimeMillis();
        return result;
    }
}
